// pages/service/index.js
const app=getApp();
Page({
    // 封装接口
    get_data_cate: async function (option) {
      wx.showLoading({
        title: '加载中',
      })
      const result = await app.wxPost({
        url:'/mini/serviceInformation/loaddatas.do',
        data:{
          othername: option
        }
      })
      if (result) {
        wx.hideLoading()
      }
      // 无数据提示
      if(!result.data.rows.length > 0) {
        wx.showToast({
          title: '暂无数据',
          icon: 'success',
          duration: 2000
        })
        return
      }
      var markers = result.data.rows.map((e,index)=>{
        return {
          id: index,
          latitude:e.lat,
          longitude:e.lng,
          iconPath:"../../static/images/dingwei.png",
          label:{
            content: e.title
          },
          width:30,
          height:30
        }
      })
      this.setData({
        latitude:markers[0].latitude,
        longitude:markers[0].longitude,
        scale: 13,
        markers: markers,
        show_markers:true
      })
    },
    // 初始化数据
    init_data: async function () {
      wx.showLoading({
        title: '加载中',
      })
      const result = await app.wxPost({
        url:'/mini/serviceInformation/loaddatas.do',
        data:{
          othername: 'siattraction'
        }
      })
      if (result) {
        wx.hideLoading()
      }
      // 无数据提示
      if(!result.data.rows.length > 0) {
        wx.showToast({
          title: '暂无数据',
          icon: 'success',
          duration: 2000
        })
        return
      }
      const index = result.data.rows.length - 1
      var markers = result.data.rows.map((e,index)=>{
        return {
          id: index,
          latitude:e.lat,
          longitude:e.lng,
          iconPath:"../../static/images/dingwei.png",
          label:{
            content: e.title
          },
          width:30,
          height:30
        }
      })
      this.setData({
        latitude:markers[index].latitude,
        longitude:markers[index].longitude,
        markers: markers,
        show_markers:true
      })
    },
    select_cate: function(event){
      const cate = event.currentTarget.dataset.cate
      this.get_data_cate(cate)
    },
    // clickmarket: function(event) {
    //   console.log(event)
    // },
  /**
   * 页面的初始数据
   */
  data: {
    navlist: [
      {name: '景点',icon: 'icon-jingdian',cate:"siattraction"},
      {name: '酒店',icon: 'icon-jiudiancanting-',cate:"sihotel"},
      {name: '加油站',icon: 'icon-dingwei',cate:"jiayouzhan"},
      {name: '美食',icon: 'icon-fenzu',cate:"cy"},
      {name: '民宿',icon: 'icon-gouwu',cate:"minsu"},
      {name: '停车场',icon: 'icon-tingchechang',cate:"parking"},
      {name: '公厕',icon: 'icon-gongce',cate:"gongce"},
      {name: '农家乐',icon: 'icon-nongjiale',cate:"nongjia"}
    ],
    longitude:116.46,
    latitude:39.92,
    markers:[],
    show_markers:false,
    scale: 12
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   this.init_data()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})